'''
Created on Dec 12, 2013

@author: rgrunitzki
'''

import time

import traci


def run():
    traci.init(8815)
    
    total_departed_vehicle = 0
    total_arrived_vehicle = 0
    drivers = []
    while True:
        
        total_departed_vehicle += traci.simulation.getDepartedNumber()
        total_arrived_vehicle += traci.simulation.getArrivedNumber()
        for d in traci.simulation.getDepartedIDList():
            drivers.append(d)
        for d in traci.simulation.getArrivedIDList():
            drivers.remove(d)
        #stop condition
        if(total_arrived_vehicle == total_departed_vehicle) and (total_departed_vehicle >0):
            break
        
        for d in drivers:
            i = 1
            #traci.vehicle.getMaxSpeed(d)
        
        traci.simulationStep()
    traci.close()
        

if __name__ == '__main__':
    tempo = time.time()
    run()
    print 'tempo simulacao (m)', str(((time.time() - tempo)/60)), 'steps'
    pass
